package com.gec.hawaste.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.hawaste.entity.Qualification;
import com.gec.hawaste.service.IQualificationService;
import com.gec.hawaste.utils.PageInfo;
import com.gec.hawaste.utils.ResultBean;
import com.gec.hawaste.vo.QualificationDo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenxys
 * @since 2022-07-01
 */
@Slf4j
@RestController
@RequestMapping("/manager/qualification")
public class QualificationController {
    @Autowired
    private IQualificationService qualificationService;

    /**
     * 资质审核分页查询
     * @author chenxys
     * @param pageNum 当前页
     * @param pageSize 每页显示条数
     * @return com.gec.hawaste.utils.ResultBean<com.baomidou.mybatisplus.extension.plugins.pagination.Page>
     */
    @GetMapping("/select/{pageNum}/{pageSize}")
    public ResultBean<Page> select(@PathVariable("pageNum") Long pageNum,
                                   @PathVariable("pageSize") Long pageSize,
                                   String startDate,
                                   String endDate,
                                   Integer type,
                                   Integer check){

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("startDate",startDate);
        params.put("endDate",endDate);
        params.put("type",type);
        params.put("check",check);
        PageInfo<QualificationDo> pageInfo = (PageInfo<QualificationDo>) qualificationService.selectByCondition(new PageInfo<>(pageNum,pageSize),params);
        pageInfo.setNavigatePage();
        log.info("资质审核分页查询");
        return ResultBean.ok(pageInfo);
    }

    /**
     * 查询单个资质审核
     * @author chenxys
     * @param id 资质审核ID
     * @return com.gec.hawaste.utils.ResultBean<com.gec.hawaste.entity.Qualification>
     */
    @GetMapping("/selectOne")
    public ResultBean<Qualification> selectOne(@RequestParam(required = true) Long id){
        Qualification qualification = qualificationService.getById(id);
        log.info("查询单个资质审核");
        return ResultBean.ok(qualification);
    }

    /**
     * 保存新的资质审核
     * @author chenxys
     * @param qualification 资质审核
     * @return com.gec.hawaste.utils.ResultBean
     */
    @PostMapping("/saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody Qualification qualification){
        qualificationService.saveOrUpdate(qualification);
        log.info("保存或更新资质审核");
        return ResultBean.ok();
    }
}
